<template>
  <div class="lb">
    <table border="1px" width="800px">
      <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>电话</th>
        <th>住址</th>
      </tr>
      <tr v-for="stu in students">
        <td>{{stu.id}}</td>
        <td>{{stu.name}}</td>
        <td>{{stu.gender}}</td>
        <td>{{stu.cellphone}}</td>
        <td>{{stu.address}}</td>
      </tr>
    </table>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "StudentView",
  data(){
    return{
      students:[]
    }
  },
  methods:{
    loadStudents(){
      //通过axios调用后台数据
      axios.get('http://localhost:8080/findStudents')
          .then(result=>{
            console.log(result.data)
            if (result.data.code){
              this.students=result.data.data;
            }else {
              this.error = "获取数据失败";
            }
          })
          .catch(error => {
            this.error = "请求失败: " + error.message;
          })
          .finally(() => {
            this.loading = false;
          });

    }
  },
  mounted() {
    this.loadStudents();
  }
}
</script>


<style>

</style>